import { resolve } from 'path';
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import pkg from './package.json';
import { normalizePath } from 'vite';
export default defineConfig({
  main: {
    define: {
      'import.meta.env.APP_NAME': `"${pkg.build.productName}"`
    },
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  preload: {
    define: {
      'import.meta.env.APP_VERSION': `"${pkg.version}"`
    },
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  renderer: {
    build: {
      rollupOptions: {
        output: {
          manualChunks(id) {
            id = normalizePath(id);
            if (id.includes('/src/stores/')) {
              return 'vendor';
            } else if (id.includes('node_modules')) {
              return 'node';
            } else {
              return 'app'
            }
          }
        }
      }
    },

    resolve: {
      alias: {
        '@': resolve('src/renderer/src')
      }
    },
    plugins: [
      vue(),
      vueJsx(),
      AutoImport({
        include: [/\.tsx$/, /\.ts$/],
        resolvers: [
          ElementPlusResolver(),
        ],
      }),
      Components({
        include: [/\.tsx$/, /\.ts$/],
        resolvers: [
          ElementPlusResolver(),
        ],
      }),
    ]
  }
})
